function avoid_refresh(){ 
    document.onkeydown = function(e)
    {
        var event=window.event||e;
        if(event.keyCode==116) {
            return false;
        }
    }
    document.oncontextmenu = function() {
        return false;
    }
}
//输入框
function cb_input(){ 
    $('.inputBg').each(function(){ 
        var $this=$(this);
        var def=$this.attr('def');
        var type=$this.attr('type');
		
        if($this.attr('def')=='undefined')return;
        $this.val(def);

        $this.focus(function(){
            var val=$this.val();
            if($.trim(val).length==0||val==def){ 
                if(type=='password'){ 
                    $this.removeClass('pwdblur');
                }else{
                    $this.val("");	
                }			
            }
        }).blur(function(){ 
            var val=$this.val();
            if($.trim(val).length==0){ 
                if(type=='password'){ 
                    $this.addClass('pwdblur');					
                }else{
                    $this.val(def);	
                }						
            }
        });
    });
}
$(function(){ 
    cb_input();
    $('#user_login .tab_menu .item').click(function(){ 
        $('input[name="type"]').val($(this).attr('rel'));
        $(this).addClass('on').siblings().removeClass('on');
        $('#user_login .tab_content .item').hide();
        $('#user_login .tab_content .'+$(this).attr('rel')+'').show();
    });
});
//checkbox全选
function cb_checkbox($select_all_btn,$item){ 
    function is_all_checked(input){ 
        var flag=false;
        input.each(function(){ 		
            flag=$(this).attr('checked');
            if(!flag)return false;
        });
        return flag;
    }
    $item.each(function(){ 
        $(this).click(function(){ 
            $select_all_btn.attr('checked',is_all_checked($item));
        })
    });
    $select_all_btn.click(function(){ 
        $item.attr('checked',is_all_checked($select_all_btn));
    });
}
function get_check_value($item){ 
    var str="";
    var i=0;
    $item.each(function(){ 
        flag=$(this).attr('checked');
        if(flag){ 
            if(i++==0){ 
                str+=$(this).val();	
            }else{
                str+=','+$(this).val();	
            }
        }
    });
    return str;
}
function minus_goods_num(obj){ 
    var parent=$(obj).parent();
    var at=parent.attr('at');
    var input=$('.text',parent);
	
    var num=parseInt(input.val())-1;
    if(num<=1)num=1;
    input.val(num);
    if(at=='cart'){
        var rec_id=parent.attr('rec_id');
        $.post('flow.php?act=set_cart_num',{goods_number:num,rec_id:rec_id},
        function(data){ 
            data=data.content;
            $('#shopping_money').html(data.shopping_money);
            $('#subtotal_'+rec_id).html(data.subtotal);
        },'json');
    }else if(at=='goods_detail'){
        changePrice();
    }
}
function plus_goods_num(obj){
    var parent=$(obj).parent();
    var at=parent.attr('at');
    var input=$('.text',parent);
    var num=parseInt(input.val())+1;
    if(num<=1)num=1;
    input.val(num);
    
    if(at=='cart'){
        var rec_id=parent.attr('rec_id');
        $.post('flow.php?act=set_cart_num',{goods_number:num,rec_id:rec_id},
        function(data){
            data=data.content;
            $('#shopping_money').html(data.shopping_money);
            $('#subtotal_'+rec_id).html(data.subtotal);
        },'json');
    }else if(at=='goods_detail'){
        changePrice();
    }
}
//确认订单页面--配送模式
$(function(){ 
    $('.shipmode').click(function(){ 
        $('.shipmode').parent().removeClass('on');
        $('.ship_content').hide();
        $(this).parent().addClass('on');
        $(this).parent().siblings().show();
        $('.shipmode').attr('checked',false);
        $('input[name="agency_id"]').attr('checked',false);
        $(this).attr('checked',true);
    });
});
function get_agency(obj){ 
    $.post(def.site_root+'flow.php?act=get_agency',{
        region_id:$(obj).val()||""
    },function(data){ 
        $("#ship_by_self .ship_content .agencies table").html(data.content);
        if($('.agencies').height()>=200||$('.agencies').height()==0){ 
            $('.agencies').addClass('overflow');
        }else{
            $('.agencies').removeClass('overflow');	
        }
    },'json');
}